# -*- coding: utf-8 -*-
"""
-------------------------------------------------
   File Name：      test
   Description :
   Author :         samge
   date：            17-11-7
-------------------------------------------------
   Change Activity: 17-11-7:
-------------------------------------------------
"""
__author__ = 'samge'
print(__name__)
def say():
    print("这是test.py的say")

if __name__ == "__main__":
    print("作为主运行test")
else:
    print("作为moudle运行test")

#基础练习
# words="ahsdfhasdf"
# print(words[0])
# arrs=[1,2,3,"d","sdf",378,"dd",3,4,98]
# print("dd" in arrs)
# #del删头不删尾
# del arrs[2:4]
# print(arrs)
# print(arrs[::-3])#从末尾隔3步取数
# arrs.insert(-1,"ssdgfsdf")#插入元素
# arrs.pop()#移除最后一位
# print(arrs)
#
# a = arrs.copy()
# print("a={}".format(a))
# print("3计数={}".format(a.count(3)))
# print(a[1:113])
# print(a[1:3]+[9,8,7,6,5,])
# a[1:3]=[2323.3232]
# print(a)
# for s in a:
#     print(s,len(str(s)))

# 简洁语法1
# arrs = []
# for x in range(5,100,10):
#     arrs.append(x**2)
# print(arrs)
# arrs2 = [x**2 for x in range(5,100,10)]
# print(arrs2)
# arrs3 = list(map(lambda x:x**2,range(5,100,10)))
# print(arrs3)

#简洁语法2
# arr4 = [(x,y) for x in [1,2,3,4,6,8,9,4] for y in [4,3,2,1,6,7,5,6] if x != y]
# print(arr4)
# ints = [-1,2,3,-4,0,-6]
# print([x*2 for x in ints])
# print([abs(x*2) for x in ints])
# print([x*2 for x in ints if x > 0])
#提取里面所有元素
# arr5=[[1,2,3],[4,5,6],[7,8,9,1,2]]
# print([num for x in arr5 for num in x])

# from math import pi
# print([str(round(pi,i)) for i in range(1,10)])

# #矩阵的横竖数据获取
# arr6 = [
#     [1,2,3],
#     [4,5,6],
#     [7,8,9]
# ]
# print([[row[i] for row in arr6] for i in range(3)])
# #使用zip()函数处理矩阵
# print(list(zip(*arr6)))

# #集合
# a = set("abcde")
# b = set("2b3c")
# print(a)
# print(b)
# #a - b 等效于 [x for x in a if x not in b]
# print(a - b)
# print([x for x in a if x not in b])
# print(a | b)
# print(a & b)
# print(a & b)

##字典的多种形式，键值对,输出时是无序的
# tel = {'samge':183652432,'samgirl':15282738}
# tel["haha"]="sldhfksd"
# tel["aaha"]="aaaaaaaaa"
# print(tel)
# print(sorted(tel))
# print(list(tel.keys()))
# #"超出数值会复制给前面所有的key"
# keys = ['samge','ahsd','shdfkh']
# print({key:range(1,10)[keys.index(key)] for key in keys})
# print({x:x**2 for x in range(4,10)})
# #使用dict()函数快速创建字典
# print(dict([('a',1),('b',2),('c',3)]))
# print(dict(a=1,b=2,c=3))

# #循环的艺术
# zd = dict(a=1,b=2,c=3)
# for i,v in zd.items():
#     print(i,":",v)
# knights = ["samge","sdjf","sdjfhs","sidhufois"]
# for i,v in enumerate(knights):
#     print(i,":",v)
# #配合zip()函数使用
# questions = ["你叫什么名字？","你来自哪里？","你的梦想是什么？"]
# answers = ["SBB","来自地球","不差钱，自由"]
# for i,v in zip(questions,answers):
#     print(i,"\n--",v)

#比较操作
# print("1<2==1:",1<2==1)
# print("1<2==2:",1<2==2)

# #2d、3d、4d指的是 占用几个空格
# for x in range(1, 11):
#     print('{0:2d} {1:3d} {2:4d}'.format(x, x*x, x*x*x))

# #美化，限定最小宽度
# import math
# import imp
# imp.reload(math)
# tel = dict(aksjdfklhasdlfklasdkjflaksdf=26476218974629863498273684683,jhdskfjhsdkjfhskdjhfksjdhfkjdhsfkjas=16384763847618364182634172)
# for i,v in tel.items():
#     print("{0:40}------------>{1:40d}".format(i,v))
# print("PI={:5.3f}".format(math.pi))
# print("PI=%5.3f"%math.pi)

# #文件操作
import os,shutil
# print(os.path)
# os.mkdir("testDir")
# os.mknod("testDir/testFile.txt")
# os.mknod("testDir/testFile2.txt")
# os.mkdir("testDir2")
# os.mknod("testDir2/testFile3.txt")
# file = open("testDir/testFile.txt",'w')
# file.write(str(dict(a=1,b=2,c=3)))
# for x in range(1,11):
#     file.writelines('{0:2d} {1:3d} {2:4d}'.format(x,x**2,x*x*x)+"\n")
# file.close()
#读文件
# fileRead = open("testDir/testFile.txt",'r')
# print(fileRead.readline(100))
# list = fileRead.readlines()
# for x in list:
#     print(x)
#操作文件
# shutil.copyfile("testDir/testFile.txt","testDir2/testFile4.txt")
# os.remove("testDir2/testFile4.txt")
# os.rename("testDir2/testFile3.txt","testDir2/testFile4.txt")
# os.rename("testDir2","testDir3")
# shutil.copytree("testDir3","testDir/newDir")
# shutil.move("testDir/newDir","testDir/newDir2")
#rmdir()只能删除空目录,,rmtree()可强制删除目录
# os.rmdir("testDir")
# shutil.rmtree("testDir3")
# fileRead.close()
#with 关键字，可以替代try ... catch ，简洁
# with open("testDir/testFile.txt") as file:
#     # print(list(file))
#     for line in file:
#         print(line,end="")
#
# file.close()

#文件通配符-从目录通配符搜索中生成文件列表
# import glob
# print(glob.glob('*.py'))

# #错误输出重定向和程序终止
# import sys
# sys.stderr.write("程序错误信息输出\n")
# #程序终止
# sys.exit()

#正则
# import re
# str = "this is a car"
# str2 = str.replace(".","person")
# print(str2)
# print(re.findall(r'\bf[a-z]*', 'which foot or hand fell fastest'))
# print(re.sub(r'(\b[a-z]+) \1', r'\1', 'cat in the the hat'))
# print('tea for too'.replace('too', 'two'))
# print(str.replace('car','person'))

# #网络访问
# from urllib.request import urlopen
# import re
# #匹配所有png结尾的图片地址
# for line in urlopen("http://www.baidu.com"):
#     line = line.decode('utf-8')
#     if re.search("http.*png",line):
#         print(re.findall("http.*png",line))

#log
import logging
logging.debug('Debugging information')
logging.info('Informational message')
logging.warning('Warning:config file %s not found', 'server.conf')
logging.error('Error occurred')
logging.critical('Critical error -- shutting down')
